package com.iwomy.secureplat.platform.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iwomy.secureplat.common.security.util.SecurityUtils;
import com.iwomy.secureplat.platform.api.entity.BasicPersonalSettingsEntity;
import com.iwomy.secureplat.platform.mapper.BasicPersonalSettingsMapper;
import com.iwomy.secureplat.platform.service.BasicPersonalSettingsService;
import org.springframework.stereotype.Service;

/**
 * 个人设置
 *
 * @author pig
 * @date 2023-11-08 10:41:35
 */
@Service
public class BasicPersonalSettingsServiceImpl extends ServiceImpl<BasicPersonalSettingsMapper, BasicPersonalSettingsEntity> implements BasicPersonalSettingsService {
	@Override
	public boolean addOrUpdate(BasicPersonalSettingsEntity basicPersonalSettings) {
		basicPersonalSettings.setUserId(SecurityUtils.getUser().getId());
		BasicPersonalSettingsEntity basicPersonalSettingsEntity = new BasicPersonalSettingsEntity();
		basicPersonalSettingsEntity.setUserId(SecurityUtils.getUser().getId());
		LambdaQueryWrapper<BasicPersonalSettingsEntity> wrapper = Wrappers.lambdaQuery(basicPersonalSettingsEntity);
		BasicPersonalSettingsEntity one = this.getOne(wrapper);

		if (ObjectUtil.isNull(one)) {
			return this.save(basicPersonalSettings);
		} else {
			basicPersonalSettings.setId(one.getId());
			return this.updateById(basicPersonalSettings);
		}
	}
}